object DoWhileDemo extends App{
  //续借规则：最多续借2次
  val maxRenewals = 2
  var renewCount = 0
  var wantToRenew = false

  //do-while循环：至少执行一次续借询问
  do{
    //模拟询问用户(实际应用中可改为控制台输入)
    //第一次询问默认续借，第二次随机决定
    wantToRenew = if (renewCount == 0) true else scala.util.Random.nextBoolean()

    if(wantToRenew && renewCount < maxRenewals) {
      renewCount += 1
      println(s"续借成功！当前续借次数：$renewCount/$maxRenewals")

    }else if (renewCount >= maxRenewals) {
      println(s"已达到最大借阅次数($maxRenewals 次)，无法继续借")
      wantToRenew = false

    }   else{
      println("用户选择不续借")
    }
  }while (wantToRenew && renewCount < maxRenewals)
  //输出最终结果
  println(s"\n续借流程结束，共续借$renewCount 次")

}
